package com.hh.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.hh.demo.constants.DemoError;
import com.hh.demo.domain.MessageSmsBlack;
import com.hh.demo.mapper.MessageSmsBlackMapper;
import com.hh.demo.service.IMessageSmsBlackService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hh.demo.util.AssertUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author goeun
 * @since 2022-07-19
 */
@Service
public class MessageSmsBlackServiceImpl extends ServiceImpl<MessageSmsBlackMapper, MessageSmsBlack> implements IMessageSmsBlackService {


    @Override
    @Transactional
    public void black(MessageSmsBlack messageSmsBlack) {
        MessageSmsBlack black = selectOne(new EntityWrapper<MessageSmsBlack>()
                .or().eq("ip", messageSmsBlack.getIp())
                .or().eq("tel",messageSmsBlack.getTel())
                .or().eq("user_id",messageSmsBlack.getUserId())
        );
        AssertUtil.isNull(black, DemoError.COMMON_BLACK_EXISTS.getMessage());
        //保存到黑名单
        insert(messageSmsBlack);
    }
}
